/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DBH.DBHelper;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Cun_con_yeu_em
 */
public class B_dathang {

    private DBHelper obj = new DBHelper();
    private Vector v;
    private String iddathang;
    private String idnv;
    private String idkh;
    private String ngaydat;

    public B_dathang() {
    }

    ;
    public B_dathang(String iddathang, String idnv, String idkh, String ngaydat) {
        this.iddathang = iddathang;
        this.idnv = idnv;
        this.idkh = idkh;
        this.ngaydat = ngaydat;

    }

    public int insertDathang(B_dathang k) throws SQLException {

        int i = 0;
        try {
            Vector v = new Vector();
            v.add(k.getIddathang());
            v.add(k.getIdnv());
            v.add(k.getIdkh());
            v.add(k.getNgaydat());
            i = DBHelper.executeUpdate("sp_insertDathang", v);
        } catch (SQLException e) {
        }
        return i;
    }

    public Vector getDathang() throws SQLException {

        Vector v = new Vector();
        try {
            ResultSet rs = obj.executeQuery("sp_getDondathang");
            while (rs.next()) {
                B_dathang k = new B_dathang();
                k.setIddathang(rs.getString(1));
                k.setNgaydat(rs.getString(4));
                v.add(k);
            }
        } catch (SQLException sqle) {
        }
        return v;
    }


//                public Vector getdathang() throws SQLException {
//        
//        Vector v = new Vector();
//        try
//        {
//        ResultSet rs = obj.executeQuery("sp_getAlldathang");
//        while(rs.next())
//        {
//            B_dathang k = new B_dathang();
//            k.setIddathang(rs.getString(1));
//           
//            k.setNgaydat(rs.getString(4));
//            v.add(k);
//        }
//        }
//        catch (SQLException sqle)  
//        {
//        }
//        return v;
//        }

    public int updatedelete(B_dathang s) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(s.getIddathang());

            i = DBHelper.executeUpdate("sp_Deletedathang", paramList);
        } catch (SQLException sqlex) {
        }
        return i;

    }

    /**
     * @return the iddathang
     */
    public String getIddathang() {
        return iddathang;
    }

    /**
     * @param iddathang the iddathang to set
     */
    public void setIddathang(String iddathang) {
        this.iddathang = iddathang;
    }

    /**
     * @return the idnv
     */
    public String getIdnv() {
        return idnv;
    }

    /**
     * @param idnv the idnv to set
     */
    public void setIdnv(String idnv) {
        this.idnv = idnv;
    }

    /**
     * @return the idkh
     */
    public String getIdkh() {
        return idkh;
    }

    /**
     * @param idkh the idkh to set
     */
    public void setIdkh(String idkh) {
        this.idkh = idkh;
    }

    /**
     * @return the ngaydat
     */
    public String getNgaydat() {
        return ngaydat;
    }

    /**
     * @param ngaydat the ngaydat to set
     */
    public void setNgaydat(String ngaydat) {
        this.ngaydat = ngaydat;
    }
}
